import { createRouter, createWebHashHistory } from "vue-router"; //引入路由
import store from "../store/index.js";
export const routes = [
  {
    path: "/",
    component: () => import("../views/MainLayout.vue"),
    children: [
      {
        path: "/Dashboard",
        component: () => import("../views/Dashboard/index.vue"),
        meta: { label: "Dashboard", icon: "Menu" },
        children: [
          {
            path: "/Dashboard/analysis",
            component: () => import("../views/Dashboard/analysis.vue"),
            meta: {
              label: "分析页",
            },
          },
          {
            path: "/Dashboard/workbench",
            component: () => import("../views/Dashboard/workbench.vue"),
            meta: {
              label: "工作台",
            },
          },
        ],
      },

      {
        path: "/user",
        component: () => import("../views/UserManager/index.vue"),
        meta: { label: "权限管理", icon: "Key" },
        children: [
          {
            path: "/user/role",
            component: () => import("../views/UserManager/role.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "权限分配",
            },
          },
          {
            path: "/user/list",
            component: () => import("../views/UserManager/list.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "管理员列表",
            },
          },
        ],
      },
      {
        path: "/member",
        component: () => import("../views/Member/index.vue"),
        meta: { label: "会员管理", icon: "User" },
        children: [
          {
            path: "/member/list",
            component: () => import("../views/Member/list.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "会员列表",
            },
          },
        ],
      },
      {
        path: "/banner",
        component: () => import("../views/Banner/index.vue"),
        meta: { label: "轮播管理", icon: "Picture" },
        children: [
          {
            path: "/list",
            component: () => import("../views/Banner/list.vue"),
            meta: {
              label: "轮播列表",
            },
          },
          {
            path: "/pub",
            component: () => import("../views/Banner/pub.vue"),
            meta: {
              label: "新增轮播",
            },
          },
                    {
            path: "/banner/edit",
            component: () => import("../views/Banner/edit.vue"),
            meta: { label: "修改轮播" },
          },
        ],
      },
      {
        path: "/recommend",
        component: () => import("../views/Recommend/index.vue"),
        meta: { label: "推荐管理", icon: "Star" },
        children: [
          {
            path: "/recommend/list",
            component: () => import("../views/Recommend/list.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "推荐列表",
            },
          },
          {
            path: "/recommend/pub",
            component: () => import("../views/Recommend/pub.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "新增推荐",
            },
          },
          {
            path: "/recommend/edit",
            component: () => import("../views/Recommend/edit.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "修改推荐",
            },
          },
        ],
      },

      {
        path: "/product",
        component: () => import("../views/Product/index.vue"),
        meta: { label: "商品管理", icon: "GoodsFilled" },
        children: [
          {
            path: "/product/list",
            component: () => import("../views/Product/list.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "商品列表",
            },
          },
          {
            path: "/product/pub",
            component: () => import("../views/Product/pub.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "新增商品",
            },
          },
          {
            path: "/product/edit",
            component: () => import("../views/Product/edit.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "修改商品",
            },
          },
        ],
      },
      {
        path: "/order",
        component: () => import("../views/Order/index.vue"),
        meta: { label: "订单管理", icon: "ShoppingCart" },
        children: [
          {
            path: "/order/list",
            component: () => import("../views/Order/list.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "订单列表",
            },
          },
        ],
      },
      // {
      //   path: "/richtext",
      //   component: () => import("../views/RichText/index.vue"),
      //   meta: { label: "富文本" },
      //   children: [
      //     {
      //       path: "/richtext/rich",
      //       component: () => import("../views/RichText/rich.vue"),
      //       meta: {
      //         //路由配置携带的额外信息
      //         label: "富文本编辑器",
      //       },
      //     },
      //   ],
      // },
      {
        path: "/echarts",
        component: () => import("../views/ECharts/index.vue"),
        meta: { label: "数据可视化", icon: "DataLine" },
        children: [
          {
            path: "/echarts/chart",
            component: () => import("../views/ECharts/chart.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "可视化图表",
            },
          },
        ],
      },
      {
        path: "/shop",
        component: () => import("../views/Shop/index.vue"),
        meta: { label: "门店管理", icon: "LocationInformation" },
        children: [
          {
            path: "/shop/map",
            component: () => import("../views/Shop/map.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "门店查询",
            },
          },
        ],
      },
      {
        path: "/Guide",
        component: () => import("../views/guide/index.vue"),
        meta: { label: "引导页", icon: "LocationInformation" },
        children: [
          {
            path: "/baidumap/map",
            component: () => import("../views/Guide/guide.vue"),
            meta: {
              //路由配置携带的额外信息
              label: "功能引导",
            },
          },
        ],
      },
    ],
  },
  {
    path: "/login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/404",
    component: () => import("../views/NotFound.vue"),
  },
  {
    path: "/:pathMatch(.*)*",
    redirect: "/404", //其他路径重定向到404界面
  },
];

const router = createRouter({
  history: createWebHashHistory(), //使用哈希路由 , url的哈希值
  routes, // ES6对象的键名、键值一样的话，可以简写
});

//设置路由拦截
// let isLogin = true; //模拟登录状态
router.beforeEach((to, from, next) => {
  if (to.fullPath != "/login") {
    if (!store.state.user.userInfo) {
      next("/login");
      return;
    }
    next();
  } else {
    next();
  }
});

export default router;
